#include <iostream>
using namespace std;
class A
{
public:
    virtual void fun()
    {
        cout << "this A: " << this << endl; 
    }
};

class B : public A
{
public:
    virtual void fun()
    {
        cout << "this B: " << this << endl; 
    }
};

int initglobal = 0;
int global;

int main()
{

    // 打印堆栈， 虚函数表的地址
    const char *str = "hello";
    char *p1 = new char[123];
    cout << "sizeof : " << sizeof(p1) << endl;

    A a;
    B *b = new B;
    cout << "A : " << (int *)&a << endl;
    cout << "&str: " << &str << endl;
    cout << "&p1: " << &p1 << endl;
    cout << endl;

    cout << "new B: " << (int *)b << endl;
    cout << "p1: " << (void *)p1 << endl;
    cout << endl;

    cout << "init: " << &initglobal << endl;
    cout << "no init: " << &global << endl;
    cout << endl;

    cout << "vft A: " << (int *)(*(int *)&a) << endl;
    cout << "vft B: " << (int *)(*(int *)b) << endl; // 添加打印的名字
    cout << "str " << (void *)str << endl;

    a.fun();
    b->fun();

    // 虚函数表放到常量去区的
    // 虚函数变ptr是随对象的（堆栈）， 对象的前四个字节是虚函数表指针
    return 0;
}